<template>
	<view class="selectAll" style="height: 100vh;background-color: #FFFFFF;max-height:calc(100vh - var(--window-top)); ">
		<view class="selectID" style="position: absolute;left: 233rpx;top:200rpx;">
			<view class="con-box" style="position: relative;">
				<picker @change="changeTab" mode="selector" :range="compList" range-key="value">
					<button type="default" class="btn-item">企业身份</button>
				</picker>
			</view>
			<button v-if="showShowPer" type="default" @click="selectUser" class="btn-item">个人身份</button>
		</view>
		<my-auth-modal></my-auth-modal>
	</view>
</template>

<script>
	import {
		getUserInfo,
	} from "@/utils/storage.js"
	import {
		queryAll
	} from '@/common/api/auth'
	import {
		getToken,
		setToken
	} from '@/utils/token.js'
	export default {
		data() {
			return {
				useNum: '',
				isXiaLa: false,
				compList: [],
				showShowPer:true
			}
		},
		onLoad: function(option) {
					//console.log("selectId", JSON.stringify(option));
			if(option.notPer){
				this.showShowPer = false;
			}
			if(option.useNum){
				this.useNum = option.useNum;
			}
			this.getCompList()
		},
		methods: {
			getCompList() {
					//console.log("\n\n\n\n\n\n\ngetCompListres", this.useNum);
				// let useNum = getToken('userInfo')['craftsmanId']
				queryAll({
					"isOwner": 1,
					"craftsmanId": getToken('userInfo')['craftsmanId']
				}).then(res => {
					
					if (res.data && res.data.listData && res.data.listData.length) { //有企业直接切换
						this.compList = res.data.listData
						this.compList.forEach((item, index) => {
							item.value = item.usrCompany.companyNameCn
						})
						//企业按名称排序
						this.compList.sort(function(a, b) {
							var value1 = a.value;
							var value2 = b.value;
							return value1.length - value2.length
						})

						if ((this.compList && this.compList.length) < 3) {
							this.compList.push({
								value: '创建企业'
							})
						}
						//console.log(this.compList)
					} else {
						this.compList.push({
							value: '创建企业'
						})
					}
				})
			},
			changeTab(e) {
				let idx = Number(e.target.value)
				this.selectComp(idx, this.compList[idx])
			},
			selectUser() {
				setToken('version', 1)
				setToken('useNum', getUserInfo()['craftsmanId'])
				this.$store.commit('isFresh', true)
				this.toUrl()
			},
			selectComp(index, item) {
				if (item.id) {
					this.$store.commit('setCompLogin', item)
					this.$store.commit('isFresh', true)
					this.toUrl()
				} else {
					uni.reLaunch({
						url: '/pages/meSub/editData/editDataComp?type=create'
					})
				}
			},
			toUrl() {
				if(getToken('jumpUrl') && getToken('jumpUrl') != '/pages/meSub/selectID'){
					// #ifdef MP-WEIXIN
					uni.reLaunch({
						url:getToken('jumpUrl')
					})
					// #endif
					// #ifdef H5
					window.location.href = getToken('jumpUrl')
					// #endif
					setToken('jumpUrl','')
				}else{
					uni.switchTab({
						url:'/pages/me/me'
					})
				}
				
			}
		}
	}
</script>

<style scoped>
	.btn-item {
		/* width: 600rpx; */
		width: 285rpx;
		height: 285rpx;
		/* min-height: 100rpx; */
		line-height: 100rpx;
		background: linear-gradient(0deg, #0B83FD 0%, #0B83FD 100%);
		/* box-shadow: 0rx 8rpx 10rpx 0rpx rgba(22, 121, 253, 0.48); */
		box-shadow: 0px 0px 81px 0px #A4D1FF inset;
		/* border-radius: 18rpx; */
		border-radius: 50%;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 40rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
		margin-top: 100rpx;

	}

	.icon-xiala,
	.icon-pullup {
		position: absolute;
		top: 0rpx;
		right: 0rpx;
		color: #FFFFFF;
		padding: 35rpx 30rpx;
	}

	.currBtn {
		background: #F8F8F8;
		border-radius: 0rpx;
		color: #000000;
		margin-top: 0rpx;
		border-bottom: 1rpx solid #EEEEEE;
	}
</style>
